<?php
/*
 * @Author: your name
 * @Date: 2020-12-23 12:01:16
 * @LastEditTime: 2020-12-23 16:07:31
 * @LastEditors: Please set LastEditors
 * @Description: 客户端错误日记逻辑层
 * @FilePath: /special/application/adminapiv3/service/platform_manage/log/ClientErrorLogService.php
 */

namespace app\adminapiv3\service\platform_manage\log;


use app\adminapiv3\service\BaseService;

class ClientErrorLogService extends BaseService
{
    /**
     * @name 列表
     * @author wx
     * @date 2020/12/15 9:43
     */
    public function list($params)
    {
        //获取当前用户
        $userInfo = $this->getLoginHostGroupId();

        $params['group_id'] = $userInfo;

        $server = new \app\common\service\platform_manage\log\ClientErrorLogService();
        $data = $server->list($params);

        $return = $this->handleData($data);


        return $return;
    }

    /**
     * @name 处理数据
     * @author wx
     * @date 2020/12/15 15:35
     */
    protected  function handleData($data)
    {
        if(empty($data['data'])){
            return $data;
        }

        $dataP = [];
        foreach ($data['data'] as $k => $v){

            if($v['source'] == 1){
                $dataSource = $v['host_name']. '['.$v['host_ip'].']';
            }else{
                $dataSource = $v['ip'];
            }

            $tmp['id'] = $v['id'];
            $tmp['data_source'] = $dataSource;
            $tmp['module'] = $v['module'];
            $tmp['source'] = $v['source'];
            $tmp['error_msg'] = $v['error_msg'];
            $tmp['error_time'] = $v['error_time'];

            $dataP[$k] = $tmp;
        }

        $data['data'] = $dataP;

        return $data;
    }
}